import axios from "axios";
import service from "@/config/index";

const URLS = {
  MENU: "/menu",
  SEARCH: "/menu/search",
  TREE: "/admin/menu/tree"
};

export default {
  load(menuId) {
    let params = {
      menuId: menuId
    };
    return axios.post(`${URLS.MENU}/${menuId}`, params);
  },
  search(filter = { page: 1, size: 10 }) {
    return axios.post(URLS.SEARCH, filter);
  },
  tree(filter = { page: 1, size: 10 }) {
    return axios.post(URLS.TREE, filter);
  },
  submit(menu = {}) {
    let { menuId } = menu;
    if (menuId) {
      return axios.put(`${URLS.MENU}/${menuId}`, menu);
    } else {
      return axios.post(URLS.MENU, menu);
    }
  }
};
